﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for TAMoreDetailEqDB
/// </summary>
public class TAMoreDetailEqDB
{
	public TAMoreDetailEqDB()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public Int64 Insert(TAMoreDetailEq TAMoreDetailEq)
    {
        MyDatabase _db = new MyDatabase();
        Int64 _result = -1;
        string _spName = "[sprocTAMoreDetailInsertUpdateSingleItemEq]";

        SortedList _sPara = new SortedList();

        #region Parameter
        _sPara.Add("@CETAMoreDetailId", TAMoreDetailEq.cetaMoreDetailId);
        _sPara.Add("@CETAInsId", TAMoreDetailEq.cetaInsId);
        _sPara.Add("@CETAID", TAMoreDetailEq.cetaId);
        _sPara.Add("@ProviderCompanyId", TAMoreDetailEq.ProviderCompanyId);
        _sPara.Add("@Name", TAMoreDetailEq.Name);
        _sPara.Add("@PostalCode", TAMoreDetailEq.PostalCode);
        _sPara.Add("@UnitNo", TAMoreDetailEq.UnitNo);
        _sPara.Add("@HomeNo", TAMoreDetailEq.HomeNo);
        _sPara.Add("@Address", TAMoreDetailEq.Address);
        _sPara.Add("@NRICNo", TAMoreDetailEq.NRICNo);
        _sPara.Add("@Nationality", TAMoreDetailEq.Nationality);
        _sPara.Add("@MobileNo", TAMoreDetailEq.MobileNo);
        _sPara.Add("@HomePhoneNo", TAMoreDetailEq.HomePhoneNo);
        _sPara.Add("@OfficePhoneNo", TAMoreDetailEq.OfficePhoneNo);
        _sPara.Add("@FaxNo", TAMoreDetailEq.FaxNo);
        _sPara.Add("@Email", TAMoreDetailEq.Email);
        _sPara.Add("@EmpName", TAMoreDetailEq.EmpName);
        _sPara.Add("@PlanName", TAMoreDetailEq.PlanName);
        _sPara.Add("@PlanType", TAMoreDetailEq.PlanType);
        _sPara.Add("@TripType", TAMoreDetailEq.TripType);
        _sPara.Add("@CoverageLevel", TAMoreDetailEq.CoverageLevel);
        _sPara.Add("@Country", TAMoreDetailEq.Country);
        _sPara.Add("@Area", TAMoreDetailEq.Area);
        _sPara.Add("@Duration", TAMoreDetailEq.Duration);
        _sPara.Add("@StartDate", TAMoreDetailEq.StartDate);
        _sPara.Add("@EndDate", TAMoreDetailEq.EndDate);
        _sPara.Add("@ChildAge", TAMoreDetailEq.ChildAge);
        _sPara.Add("@AdultAge", TAMoreDetailEq.AdultAge);
        _sPara.Add("@NoOfTraveller", TAMoreDetailEq.NoOfTraveller);
        _sPara.Add("@TotalPremium", TAMoreDetailEq.TotalPremium);
        _sPara.Add("@PamentType", TAMoreDetailEq.PamentType);
        _sPara.Add("@RefCEUserId", TAMoreDetailEq.RefCEUserId);
        _sPara.Add("@ViewedDetailId", TAMoreDetailEq.ViewedDetailId);
        _sPara.Add("@Status", TAMoreDetailEq.Status);
        _sPara.Add("@Info1", TAMoreDetailEq.Info1);
        _sPara.Add("@Info2", TAMoreDetailEq.Info2);
        #endregion

        _result = _db.ExecuteSP(_spName, _sPara);

        return _result;
    }

    public bool Update()
    {
        return true;
    }

    public bool Delete()
    {
        return true;
    }

    public TAMoreDetailEq GetTAMoreDetail(Int64 TAId, Int64 CEUserId)
    {
        TAMoreDetailEq _tamoredetail = null;
        MyDatabase _db = new MyDatabase();
        string _spName = "[sprocTAMoreDetailSelectSingleItemEq]";

        SortedList _spara = new SortedList();
        _spara.Add("@CETAid", TAId);
        _spara.Add("@RefCEUserId", CEUserId);

        DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
        if (_dt != null)
        {
            if (_dt.Rows.Count > 0)
            {
                _tamoredetail = new TAMoreDetailEq();
                _tamoredetail = FillDataRecord(_dt);
            }
        }
        return _tamoredetail;
    }

    private TAMoreDetailEq FillDataRecord(DataTable myDataTable)
    {
        TAMoreDetailEq myTAMoreDetail = new TAMoreDetailEq();
        myTAMoreDetail.cetaMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["cetaMoreDetailId"].ToString());
        myTAMoreDetail.cetaInsId = Convert.ToInt64(myDataTable.Rows[0]["cetaInsId"].ToString());
        myTAMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
        myTAMoreDetail.cetaId = Convert.ToInt64(myDataTable.Rows[0]["cetaId"].ToString());
        myTAMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
        myTAMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
        myTAMoreDetail.UnitNo = myDataTable.Rows[0]["UnitNo"].ToString();
        myTAMoreDetail.HomeNo = myDataTable.Rows[0]["HomeNo"].ToString();
        myTAMoreDetail.Address = myDataTable.Rows[0]["Address"].ToString();
        myTAMoreDetail.NRICNo = myDataTable.Rows[0]["NRICNo"].ToString();
        myTAMoreDetail.Nationality = myDataTable.Rows[0]["Nationality"].ToString();
        myTAMoreDetail.MobileNo = myDataTable.Rows[0]["MobileNo"].ToString();
        myTAMoreDetail.HomePhoneNo = myDataTable.Rows[0]["HomePhoneNo"].ToString();
        myTAMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
        myTAMoreDetail.FaxNo = myDataTable.Rows[0]["FaxNo"].ToString();
        myTAMoreDetail.Email = myDataTable.Rows[0]["Email"].ToString();
        myTAMoreDetail.EmpName = myDataTable.Rows[0]["EmpName"].ToString();
        myTAMoreDetail.PlanName = myDataTable.Rows[0]["PlanName"].ToString();
        myTAMoreDetail.PlanType = myDataTable.Rows[0]["PlanType"].ToString();
        myTAMoreDetail.CoverageLevel = myDataTable.Rows[0]["CoverageLevel"].ToString();
        myTAMoreDetail.Country = myDataTable.Rows[0]["Country"].ToString();
        myTAMoreDetail.Area = myDataTable.Rows[0]["Area"].ToString();
        myTAMoreDetail.Duration = myDataTable.Rows[0]["Duration"].ToString();
        myTAMoreDetail.StartDate = Convert.ToDateTime(myDataTable.Rows[0]["StartDate"].ToString());
        myTAMoreDetail.EndDate = Convert.ToDateTime(myDataTable.Rows[0]["EndDate"].ToString());
        myTAMoreDetail.ChildAge = Convert.ToInt32(myDataTable.Rows[0]["ChildAge"].ToString());
        myTAMoreDetail.AdultAge = Convert.ToInt32(myDataTable.Rows[0]["AdultAge"].ToString());
        myTAMoreDetail.NoOfTraveller = Convert.ToInt32(myDataTable.Rows[0]["NoOfTraveller"].ToString());

        myTAMoreDetail.TotalPremium = Convert.ToSingle(myDataTable.Rows[0]["TotalPremium"].ToString());
        myTAMoreDetail.PamentType = myDataTable.Rows[0]["PamentType"].ToString();
        myTAMoreDetail.ViewedDetailId = Convert.ToInt64(myDataTable.Rows[0]["ViewedDetailId"].ToString());
        myTAMoreDetail.RowGUID = myDataTable.Rows[0]["RowGUID"].ToString();
        myTAMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
        myTAMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());

        if (myDataTable.Rows[0]["Info1"].ToString() != "")
            myTAMoreDetail.Info1 = myDataTable.Rows[0]["Info1"].ToString();
        else
            myTAMoreDetail.Info1 = "0";

        if (myDataTable.Rows[0]["Info2"].ToString() != "")
            myTAMoreDetail.Info2 = myDataTable.Rows[0]["Info2"].ToString();
        else
            myTAMoreDetail.Info2 = "0";


        return myTAMoreDetail;
    }
}
